package com.zmc.common.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;
import java.util.List;

/**
 * 分页工具类
 * @Author zmc
 */

@Setter
@Getter
public class PageUtils implements Serializable {

	private static final long serialVersionUID = 1L;
	//总记录数
	private Long totalCount;
	//每页记录数
	private Long pageSize;
	//总页数
	private Long totalPage;
	//当前页数
	private Long currPage;
	//列表数据
	private List<?> list;
	
	/**
	 * 分页
	 * @param list        列表数据
	 * @param totalCount  总记录数
	 * @param pageSize    每页记录数
	 * @param currPage    当前页数
	 */
	public PageUtils(List<?> list, Long totalCount, Long pageSize, Long currPage) {
		this.list = list;
		this.totalCount = totalCount;
		this.pageSize = pageSize;
		this.currPage = currPage;
		this.totalPage = (long) Math.ceil((double) totalCount /pageSize);
	}

	public PageUtils(IPage<?> page) {
		this(page.getRecords(), page.getTotal(), page.getSize(), page.getCurrent());
	}


}
